package com.ibm.cloud.banking.account.convert;

import com.ibm.cloud.banking.account.dto.AccountInfoDTO;
import com.ibm.cloud.banking.account.entity.AccountInfoEntity;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.util.Map;

/**
 * replace desc in here
 *
 * @author HanDong
 * @date 2022/7/17
 */
@Mapper(componentModel = "spring")
public interface AccountInfoMapper {


    AccountInfoEntity dtoToEntity(AccountInfoDTO dto);

    AccountInfoDTO entityToDto(AccountInfoEntity entity);

    @Mappings(
            value = {
                    @Mapping(expression = "java((String)map.get(\"mainCardNo\"))", target = "mainCardNo"),
                    @Mapping(expression = "java((String)map.get(\"password\"))", target = "password"),
                    @Mapping(expression = "java((String)map.get(\"cardLevel\"))", target = "cardLevel"),
                    @Mapping(expression = "java((String)map.get(\"productNo\"))", target = "productNo"),
                    @Mapping(expression = "java((String)map.get(\"accountNo\"))", target = "accountNo"),
                    @Mapping(expression = "java((String)map.get(\"customerName\"))", target = "name"),
                    @Mapping(expression = "java(((Integer)map.get(\"accountCategory\")).toString())", target = "type")
            }
    )
    AccountInfoDTO mapToDto(Map map);
}
